from typing import List


class Solution:
    def triangleNumber(self, nums: List[int]) -> int:
        nums.sort()
        arr_len = len(nums)

        ret = 0
        # [2,2,3,4]
        for i_idx in range(0, arr_len - 2):
            right = i_idx + 1
            for left in range(i_idx + 1, arr_len - 1):
                while right + 1 < arr_len and nums[i_idx] + nums[left] > nums[right + 1]:
                    right += 1
                if right - left > 0:
                    ret += right - left
        return ret
